<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <!-- 自定义字段名为 title 的插槽 -->
      <template #status="{ record }">
            <!-- 对标题加上 tag -->
            <a-tag v-if="record.status == 1" color="blue">正常</a-tag>
            <a-tag v-if="record.status == 2" color="blue">禁用</a-tag>
      </template>
      <template #warehouse_type_id="{ record }">
            <!-- 对标题加上 tag -->
            <a-tag color="blue">{{ record.types.name }}</a-tag>
      </template>
      <template #warehouse_master_id="{ record }">
            <!-- 对标题加上 tag -->
            <a-tag color="blue">{{ record.master.name }}</a-tag>
      </template>
      <template #reaches_position="{ record }">
            <!-- 对标题加上 tag -->
            <a-tag color="blue">{{ record.reaches_position == 1?'上':'下 ' }}</a-tag>
      </template>
      
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import warehouseChilds from '@/api/warehouse/warehouseChilds'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const master_id = ref()
const inforow = ref()

const open = (row) => {
  master_id.value = row.id
  inforow.value = row
  crudRef.value.requestData()
}


const numberOperation = (newValue, id, numberName) => {
  warehouseChilds.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  warehouseChilds.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_warehouse_childs',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: warehouseChilds.getList,
  recycleApi: warehouseChilds.getRecycleList,
  add: {
    show: true,
    api: warehouseChilds.save,
    auth: ['warehouse:childs:save']
  },
  edit: {
    show: true,
    api: warehouseChilds.update,
    auth: ['warehouse:childs:update']
  },
  delete: {
    show: true,
    api: warehouseChilds.deletes,
    auth: ['warehouse:childs:delete'],
    realApi: warehouseChilds.realDeletes,
    realAuth: ['warehouse:childs:realDeletes']
  },
  recovery: {
    show: true,
    api: warehouseChilds.recoverys,
    auth: ['warehouse:childs:recovery']
  },
  import: {
    show: true,
    url: 'warehouse/childs/import',
    templateUrl: 'warehouse/childs/downloadTemplate',
    auth: ['warehouse:childs:import']
  },
  export: {
    show: true,
    url: 'warehouse/childs/export',
    auth: ['warehouse:childs:export']
  },
  beforeRequest: (params) => {
      params.warehouse_master_id = master_id.value
      params.order = 'created_at'
      params.orderType = 'desc'
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: '所属仓库',
    dataIndex: 'warehouse_master_id',
    align: "center",
    formType: 'select',
    search: true,
    dict: {
        // 远程通用接口请求，新版代码生成都有一个 remote 接口
        remote: 'warehouse/master/remote',
        // 指定组件接收的props
        props: { label: 'name', value: 'id' },
        // 开启分页
        openPage: true,
        // 远程请求配置项
        remoteOption: {
            // 按用户名排序
            sort: { id: 'desc' }, // 如果不指定排序方式，默认为正序排序
            // 设置查询的字段
            select: [ 'id', 'name' ],
            // 设置数据过滤
            filter: {
              
            },
            // 关联模型
            relations: [
              
            ]
        }
      },
      commonRules: {
        required: true,
        message: "请选择仓库类型"
      }
    },
  {
    title: '仓库类型',
    dataIndex: 'warehouse_type_id',
    formType: 'select',
    align: "center",
    search: true,
    dict: {
        // 远程通用接口请求，新版代码生成都有一个 remote 接口
        remote: 'warehouse/type/remote',
        // 指定组件接收的props
        props: { label: 'name', value: 'id' },
        // 开启分页
        openPage: true,
        // 远程请求配置项
        remoteOption: {
            // 按用户名排序
            sort: { id: 'desc' }, // 如果不指定排序方式，默认为正序排序
            // 设置查询的字段
            select: [ 'id', 'name' ],
            // 设置数据过滤
            filter: {
              
            },
            // 关联模型
            relations: [
              
            ]
        }
      },
      commonRules: {
        required: true,
        message: "请选择仓库类型"
      }
    },
  {
    title: "横向位置",
    dataIndex: "horizontal_position",
    formType: "input-number",
    align: "center",
    search: true,
    commonRules: {
      required: true,
      message: "请输入横向位置"
    }
  },
  {
    title: "纵向位置",
    dataIndex: "release_position",
    formType: "input-number",
    search: true,
    align: "center",
    commonRules: {
      required: true,
      message: "请输入纵向位置"
    }
  },
  {
    title: "层级位置",
    dataIndex: "reaches_position",
    formType: "input-number",
    align: "center",
    search: true,
    commonRules: {
      required: true,
      message: "请输入层级位置"
    }
  },
  {
    title: "状态",
    dataIndex: "status",
    align: "center",
    formType: "switch",
    search: true,
    commonRules: {
      required: true,
      message: "请输入状态"
    },
    checkedValue: "1",
    uncheckedValue: "2"
  },
  {
    title: "库存总量",
    dataIndex: "zong_num",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "库存余量",
    dataIndex: "yu_num",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "订单总量",
    dataIndex: "order_zong_num",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "订单余量",
    dataIndex: "order_yu_num",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    align: "center",
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
defineExpose({ open })
</script>
<script> export default { name: 'warehouse:childs' } </script>